﻿using ConfExpert.Forms.Base;

using DevTeam;

using System;
namespace ConfExpert.Forms.Depo
{
    public partial class _Barkod : XForm
    {
        int BrandId;
        public _Barkod(int brandId)
        {
            InitializeComponent();
            BrandId = brandId;
        }

        private void ModelDetaylari_Load(object sender, EventArgs e)
        {
            
            gvBarkod.Init("GetCcBarkodListesi", BrandId, 1);
            gvBarkod.SetFilterTypeToCheckedList("DosyaNo");
            gvBarkod.MakeColumnInvisible("idx");
            gvBarkod.BestFitColumns();

            gvBarkod.MakeReadOnly();

            GridManager gm = GridManager.GetManager(gvBarkod);
            gm.GridMenu.AddMenu("Barkodlar yazdırıldı", Printed);
            btnKaydet.ItemClick += btnKaydet_ItemClick;
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            int rowhandle = gvBarkod.FocusedRowHandle;
            gvBarkod.RefreshDataSource("GetCcBarkodListesi", BrandId, 1);
            gvBarkod.FocusedRowHandle = rowhandle;
        }

        private void Printed(object sender, EventArgs e)
        {
            string idxs = GetIdx();
            ExecuteNonQuery("SetBarcodeIsPrinted", idxs);
            btnKaydet.PerformClick();
        }

        private string GetIdx()
        {
            string idxs = "";
            foreach (int rowHandle in gvBarkod.GetSelectedRows())
                if (rowHandle > -1)
                    idxs += gvBarkod.GetRowCellValue(rowHandle, "idx").ToString() + ",";


            idxs = idxs.RemoveIfEndsWith(",");

            return idxs;
        }

    }
}